var app = getApp();

// pages/homepage/zixun/zixun.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    _num: 0,
    getResource: [],
    bannerimage: [],

    // 临时，需从缓存取出
    city: 1,
    // 缓存文件
    session: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    // 加载banner图片

    wx.request({
      url: app.d.ceshiUrl + '/public/index.php/api/get_banner',
      data: {
        category: '中高考资讯'
      },
      success: function (res) {
        that.setData({
          bannerimage: res.data.data
        })
      },
      fail: function (e) {
        app.errorToast()
      }
    })

    // 初始化第一个资讯内容
    wx.request({
      url: app.d.ceshiUrl + '/public/index.php/api/get_article',
      data: {
        ident: 'information',
        type_id: 0,
        city: that.data.city
      },
      success: function (res) {
        that.setData({
          getResource: res.data.data
        })
      },
      fail: function (e) {
        app.errorToast()
      }
    })
  },
  tabClick(e) {
    var that = this;

    this.setData({
      _num: e.currentTarget.id
    })


    // 请求数据
    wx.request({
      url: app.d.ceshiUrl + '/public/index.php/api/get_article',
      data: {
        ident: 'information',
        type_id: that.data._num,
        city: that.data.city
      },
      success: function (res) {
        that.setData({
          getResource: res.data.data
        })
      },
      fail: function (e) {
        app.errorToast()
      }
    })
  },

  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '龙门尚学教育',
      path: '/pages/homepage/zixun/zixun'
    }
  }
})
